﻿using CG5_KT.Primitives;
using System.Collections.Generic;

namespace CG5_KT.Scene
{
    public class ModelFactory
    {
        public static Model ConstructAircraft()
        {
            Color4 colorGold = new Color4(1, 215.0f / 255, 0, 1);
            float deckWidthHalf = 0.1f;
            float deckDepthHalf = 0.3f;

            Mesh deck = MeshFactory.ConstructCube();
            deck.SurfaceColor = colorGold;
            deck.Scale(new Vector3(deckWidthHalf, 0.05f, deckDepthHalf));

            Mesh tailFinLeft = MeshFactory.ConstructCube();
            tailFinLeft.SurfaceColor = colorGold;
            tailFinLeft.Scale(new Vector3(0.1f, 0.01f, 0.035f));
            tailFinLeft.TranslateVertices(new Vector3(-deckWidthHalf - 0.1f, 0, deckDepthHalf - 0.08f));
            

            Mesh tailFinRight = MeshFactory.ConstructCube();
            tailFinRight.SurfaceColor = colorGold;
            tailFinRight.Scale(new Vector3(0.1f, 0.01f, 0.035f));
            tailFinRight.TranslateVertices(new Vector3(deckWidthHalf + 0.1f, 0, deckDepthHalf - 0.08f));

            Mesh wingLeft = MeshFactory.ConstructCube();
            wingLeft.SurfaceColor = colorGold;
            wingLeft.Scale(new Vector3(0.2f, 0.02f, 0.035f));
            wingLeft.TranslateVertices(new Vector3(-deckWidthHalf - 0.2f, 0, -deckDepthHalf + 0.1f));

            Mesh wingRight = MeshFactory.ConstructCube();
            wingRight.SurfaceColor = colorGold;
            wingRight.Scale(new Vector3(0.2f, 0.02f, 0.035f));
            wingRight.TranslateVertices(new Vector3(deckWidthHalf + 0.2f, 0, -deckDepthHalf + 0.1f));

            var meshes = new List<Mesh>();
            meshes.Add(deck);
            meshes.Add(tailFinLeft);
            meshes.Add(tailFinRight);
            meshes.Add(wingLeft);
            meshes.Add(wingRight);

            var model = new Model();
            model.Meshes = meshes;

            return model;
        }

        public static Model ConstructTerrainAndBaloons()
        {
            float terrainWidth = 6f;
            float terrainHeight = 0.2f;
            float terrainDepth = 6f;
            float terrainY = -terrainHeight / 2;
            Vector3 terrainScale = new Vector3(terrainWidth / 2, terrainHeight / 2, terrainDepth / 2);

            float buildingWidth = 0.5f;
            float buildingHeight = 1.25f;
            float buildingDepth = 0.5f;
            float buildingY = buildingHeight / 2;
            Vector3 buildingScale = new Vector3(buildingWidth / 2, buildingHeight / 2, buildingDepth / 2);

            float baloonRadius = 0.5f;
            Vector3 baloonScale = new Vector3(baloonRadius, baloonRadius, baloonRadius);
            Vector3 baloonLampScale = baloonScale / 2;

            // Make terrain from a green cube mesh. Increase cube width and depth, decrease height.
            // Position it on the bottom of the screen.
            Mesh terrainMesh = MeshFactory.ConstructCube();
            terrainMesh.SurfaceColor = new Color4(0, 1, 0, 1);
            terrainMesh.Scale(terrainScale);
            terrainMesh.Position = new Vector3(0, terrainY, 0);

            // Make buildings, different colors are used.
            Mesh buildingA = MeshFactory.ConstructCube();
            buildingA.SurfaceColor = new Color4(1, 0, 0, 1);
            buildingA.Scale(buildingScale);
            buildingA.Position = new Vector3(1f, buildingY, 1f);

            Mesh buildingB = MeshFactory.ConstructCube();
            buildingB.SurfaceColor = new Color4(1, 0, 0, 1);
            buildingB.Scale(buildingScale);
            buildingB.Position = new Vector3(2.5f, buildingY, 2.5f);

            Mesh buildingC = MeshFactory.ConstructCube();
            buildingC.SurfaceColor = new Color4(0, 0, 1, 1);
            buildingC.Scale(buildingScale);
            buildingC.Position = new Vector3(-2.5f, buildingY, 0f);

            Mesh buildingD = MeshFactory.ConstructCube();
            buildingD.SurfaceColor = new Color4(0, 0, 1, 1);
            buildingD.Scale(buildingScale);
            buildingD.Position = new Vector3(-2f, buildingY, 2f);

            Mesh buildingE = MeshFactory.ConstructCube();
            buildingE.SurfaceColor = new Color4(0, 1, 1, 1);
            buildingE.Scale(buildingScale);
            buildingE.Position = new Vector3(2f, buildingY, -2f);

            Mesh buildingF = MeshFactory.ConstructCube();
            buildingF.SurfaceColor = new Color4(0, 1, 1, 1);
            buildingF.Scale(buildingScale*2);
            buildingF.Position = new Vector3(0, buildingY+0.5f, 0);


            // Make baloonlamps.
            Mesh baloonLampMeshA = MeshFactory.ConstructSphere();
            baloonLampMeshA.SurfaceColor = new Color4(1, 1, 0, 1); // Yellow
            baloonLampMeshA.Scale(baloonLampScale);
            baloonLampMeshA.Position = new Vector3(2.5f, buildingY + 1f, 2.5f);

            Mesh baloonLampMeshB = MeshFactory.ConstructSphere();
            baloonLampMeshB.SurfaceColor = new Color4(1, 1, 0, 1); // Yellow
            baloonLampMeshB.Scale(baloonLampScale);
            baloonLampMeshB.Position = new Vector3(2, buildingY + 1f, -2);

            Mesh baloonLampMeshC = MeshFactory.ConstructSphere();
            baloonLampMeshC.SurfaceColor = new Color4(1, 1, 0, 1); // Yellow
            baloonLampMeshC.Scale(baloonLampScale);
            baloonLampMeshC.Position = new Vector3(-2.5f, buildingY + 1f, 0f);

            var meshes = new List<Mesh>();
            meshes.Add(terrainMesh);
            meshes.Add(buildingA);
            meshes.Add(buildingB);
            meshes.Add(buildingC);
            meshes.Add(buildingD);
            meshes.Add(buildingE);
            meshes.Add(buildingF);
            meshes.Add(baloonLampMeshA);
            meshes.Add(baloonLampMeshB);
            meshes.Add(baloonLampMeshC);

            var model = new Model();
            model.Meshes = meshes;

            return model;
        }
    }
}
